package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.AnalysisBlackList;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.AnalysisBlackListDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2018-11-26 15:03:54
 */
public class AnalysisBlackListConverts {

    private static Logger LOG = LoggerFactory.getLogger(AnalysisBlackListConverts.class);

    public static List<AnalysisBlackListDTO> convert(List<AnalysisBlackList> analysisBlackListList) {
        if (CollectionUtils.isEmpty(analysisBlackListList)) {
            return Collections.EMPTY_LIST;
        }

        List<AnalysisBlackListDTO> analysisBlackListListResult = Lists.newArrayList();
        for (AnalysisBlackList analysisBlackList : analysisBlackListList) {
            analysisBlackListListResult.add(convert(analysisBlackList));
        }
        return analysisBlackListListResult;
    }

    public static AnalysisBlackListDTO convert(AnalysisBlackList analysisBlackList) {
        try {
            return BeanUtils.copy(analysisBlackList, AnalysisBlackListDTO.class);
        } catch (Exception e) {
            LOG.error("AnalysisBlackList到AnalysisBlackListDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisBlackList到AnalysisBlackListDTO转换失败", e);
        }
    }

    public static AnalysisBlackList convert(AnalysisBlackListDTO analysisBlackListDTO) {
        try {
            return BeanUtils.copy(analysisBlackListDTO, AnalysisBlackList.class);
        } catch (Exception e) {
            LOG.error("AnalysisBlackListDTO到AnalysisBlackList转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisBlackListDTO到AnalysisBlackList转换失败", e);
        }
    }
}